const API = require("../../http/API")
const http = require("../../http/http")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dachujz: '',
    dachuzf: '',
    dachurm: '',
    page: 1,
    page2: 1,
    page3: 1,
    // 显示哪个
    shownum: 1,
  },
  showone() {
    this.setData({
      shownum: 1
    })
  },
  showtwo() {
    this.setData({
      shownum: 2
    })
  },
  showthree() {
    this.setData({
      shownum: 3
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // 大触讲座
    http(API.dachujz, {
      link: 'paging',
      live: 3,
      heat: 'N',
      page: this.data.page,
    }).then(res => {
      this.setData({
        dachujz: res.data.course.data
      })
    })

    // 大触专访
    http(API.dachuzf, {
      link: 'paging',
      type: 'interview',
      page: this.data.page2,
    }).then(res => {
      console.log(res);
      this.setData({
        dachuzf: res.data.data
      })
    })


    // 热门大触
    http(API.dachurm, {
      link: 'paging',
      page: this.data.page3,
    }).then(res => {
      this.setData({
        dachurm: res.data.data
      })
    })
  },






  // 触底加载
  onReachBottom: function () {
    if (this.data.shownum === 1) {
      this.setData({
        page: this.data.page += 1
      })
      http(API.dachujz, {
        link: 'paging',
        live: 3,
        heat: 'N',
        page: this.data.page,
      }).then(res => {
        this.setData({
          dachujz: [...this.data.dachujz, ...res.data.course.data]
        })
        if (res.data.course.data == false) {
          wx.showToast({
            title: '没有更多的数据了',
            icon: 'none'
          })
        }
      })
    }
    if (this.data.shownum === 2) {
      this.setData({
        page2: this.data.page2 += 1
      })
      http(API.dachuzf, {
        link: 'paging',
        type: 'interview',
        page: this.data.page2,
      }).then(res => {
        this.setData({
          dachuzf: [...this.data.dachuzf, ...res.data.data]
        })
        if (res.data.data == false) {
          wx.showToast({
            title: '没有更多的数据了',
            icon: 'none'
          })
        }
      })
    }
    if (this.data.shownum === 3) {
      this.setData({
        page3: this.data.page3 += 1
      })
      http(API.dachurm, {
        link: 'paging',
        page: this.data.page3,
      }).then(res => {
        this.setData({
          dachurm: [...this.data.dachurm, ...res.data.data]
        })
        if (res.data.data == false) {
          wx.showToast({
            title: '没有更多的数据了',
            icon: 'none'
          })
        }
      })
    }
  }
})